package com.ruoyi.system.controller;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.ZtfCodeNc;
import com.ruoyi.system.service.IZtfCodeNcService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 激活码，可短信发出或线下发给Controller
 * 
 * @author ruoyi
 * @date 2025-05-30
 */
@RestController
@RequestMapping("/system/nc")
@Api(tags = "激活码相关接口")
public class ZtfCodeNcController extends BaseController
{
    @Autowired
    private IZtfCodeNcService ztfCodeNcService;

    /**
     * 查询激活码，可短信发出或线下发给列表
     */
    @PreAuthorize("@ss.hasPermi('system:nc:list')")
    @GetMapping("/list")
    @ApiOperation("激活码列表")
    public TableDataInfo list(ZtfCodeNc ztfCodeNc)
    {
        startPage();
        List<ZtfCodeNc> list = ztfCodeNcService.selectZtfCodeNcList(ztfCodeNc);
        return getDataTable(list);
    }

    /**
     * 导出激活码，可短信发出或线下发给列表
     */
    @PreAuthorize("@ss.hasPermi('system:nc:export')")
    @Log(title = "激活码，可短信发出或线下发给", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZtfCodeNc ztfCodeNc)
    {
        List<ZtfCodeNc> list = ztfCodeNcService.selectZtfCodeNcList(ztfCodeNc);
        ExcelUtil<ZtfCodeNc> util = new ExcelUtil<ZtfCodeNc>(ZtfCodeNc.class);
        util.exportExcel(response, list, "激活码，可短信发出或线下发给数据");
    }

    /**
     * 获取激活码，可短信发出或线下发给详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:nc:query')")
    @GetMapping(value = "/{codeUuid}")
    public AjaxResult getInfo(@PathVariable("codeUuid") String codeUuid)
    {
        return success(ztfCodeNcService.selectZtfCodeNcByCodeUuid(codeUuid));
    }

    /**
     * 新增激活码，可短信发出或线下发给
     */
    @PreAuthorize("@ss.hasPermi('system:nc:add')")
    @Log(title = "激活码，可短信发出或线下发给", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增激活码")
    public AjaxResult add(@RequestBody ZtfCodeNc ztfCodeNc)
    {
        return toAjax(ztfCodeNcService.insertZtfCodeNc(ztfCodeNc));
    }

    /**
     * 修改激活码，可短信发出或线下发给
     */
    @PreAuthorize("@ss.hasPermi('system:nc:edit')")
    @Log(title = "激活码，可短信发出或线下发给", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改激活码")
    public AjaxResult edit(@RequestBody ZtfCodeNc ztfCodeNc)
    {
        return toAjax(ztfCodeNcService.updateZtfCodeNc(ztfCodeNc));
    }

    /**
     * 删除激活码，可短信发出或线下发给
     */
    @PreAuthorize("@ss.hasPermi('system:nc:remove')")
    @Log(title = "激活码，可短信发出或线下发给", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codeUuids}")
    @ApiOperation("删除激活码")
    public AjaxResult remove(@PathVariable String[] codeUuids)
    {
        return toAjax(ztfCodeNcService.deleteZtfCodeNcByCodeUuids(codeUuids));
    }

    /**
     * 批量修改激活码
     * @param ids
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:nc:editBatch')")
    @Log(title = "激活码，可短信发出或线下发给", businessType = BusinessType.DELETE)
    @PutMapping("/{ids}")
    @ApiOperation("批量修改激活码")
    public AjaxResult editBatch(@PathVariable String[] ids)
    {
        return toAjax(ztfCodeNcService.updateZtfCodeNcByids(ids));
    }
}
